<!-- 材料汇总作业：蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" @findClicked="findClicked" :formList="formList" />

    <div class="flex mt10 main">
      <el-card shadow="never" style="width: 50%" :body-style="{ padding: '5px 10px 5px' }">
        <span style="font-weight: 600">待汇总指令</span>
        <Table
          @selectList="selectList"
          selection
          :isLoading="isLoading"
          @currentRow="currentRow"
          :tableHeader="tableHeader"
          :tableData="tableData"
          :TableHeight="50"
        ></Table>
        <PageModule
          :PageData="{ total, buttonS: true, pageSizeShow: false }"
          @pageSizeChange="handleSizeChange"
          :layout="'prev, pager'"
          @pageChange="handleCurrentChange"
        />
      </el-card>

      <el-card shadow="never" style="width: 50%" :body-style="{ padding: '5px 10px 5px' }">
        <span style="font-weight: 600">汇总材料查询</span>
        <Table
          @selectList="selectList2"
          :isLoading="isLoading2"
          @currentRow="currentRow2"
          :tableHeader="tableHeader2"
          :tableData="tableData2"
          :TableHeight="50"
        ></Table>
      </el-card>
    </div>

    <div class="flex main">
      <div style="width: 50%; margin-left: 15px; margin-top: 1px">
        <span style="font-weight: 600">汇总号查询</span>
        <Table
          selection
          @selectList="selectList3"
          :isLoading="isLoading3"
          @currentRow="currentRow3"
          :tableHeader="tableHeader3"
          :tableData="tableData3"
          :TableHeight="50"
        ></Table>
      </div>

      <div style="width: 50%; margin-left: 15px">
        <span style="font-weight: 600">汇总贴合子资料查询</span>
        <Table :isLoading="isLoading5" :tableHeader="tableHeader5" :tableData="tableData5" :TableHeight="45"></Table>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import fileRequest from '@/utils/fileRequest'
import JMessage from '@/utils/JMessage'
import service from '@/utils/request'
export default defineComponent({
  name: 'MaterialAggregationOperation'
})
</script>
<script lang="ts" setup>
import { ref, onMounted, watch } from 'vue'
const isLoading = ref(true)
const isLoading2 = ref(true)
const isLoading3 = ref(true)
const isLoading4 = ref(true)
const isLoading5 = ref(true)
const findClicked = async (countText: string) => {
  switch (countText) {
    case '查询待汇总指令': {
      getTableList()
      break
    }
    case '查询已汇总指令': {
      getTableList3()
      break
    }
    case '不汇总指令删除': {
      // change10()
      break
    }
    case '删除指令查询': {
      // dialogVisible5.value = true
      // getTableList7()
      break
    }
    case '汇总作业': {
      // SummaryOperationMethods()
      break
    }
    case '删除汇总': {
      removeSummary()
      break
    }
    case '批量汇总': {
      batchSummary()
      break
    }
  }
}
const removeSummary = async () => {
  const res = await service.post<any, any>(`/mes/kf/summaryOperation/deleteSummaryLotNo?sumNo=${currentTableRow3.value.sumNo}`)
  if (res.code === 200) {
    JMessage.success('删除成功')
    getTableList()
    getTableList3()
  } else {
    JMessage.error(res.msg)
  }
}
// 批量汇总
const batchSummary = async () => {
  if (selectTableList.value.length === 0) {
    JMessage.warning('请选择需要批量汇总的指令')
  } else {
    const res = await service.post<any, any>(
      `/mes/kf/summaryOperation/summaryOperationBatch`,
      selectTableList.value.map((item: any) => item.orderId)
    )
    if (res.code === 200) {
      JMessage.success('批量汇总成功')
      getTableList()
      getTableList3()
    } else {
      JMessage.error(res.msg)
    }
  }
}
// 待汇总指令查询
const tableData = ref([])
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令号',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入汇总号',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入物料编码',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'button',
    checkboxLabel: '查询待汇总指令'
  },
  {
    type: 'button',
    checkboxLabel: '查询已汇总指令'
  },
  {
    type: 'button',
    checkboxLabel: '删除汇总'
  },
  {
    type: 'button',
    checkboxLabel: '批量汇总'
  }
  // {
  //   type: 'button',
  //   checkboxLabel: '汇总作业'
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '导出汇总资料明细'
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '不汇总指令删除'
  // },
  // {
  //   type: 'button',
  //   checkboxLabel: '删除指令查询'
  // }
])
const tableHeader = ref([
  {
    label: '指令',
    prop: 'orderId',
    sortable: true
  },
  {
    label: '样品类型',
    prop: 'sampleType',
    sortable: true
  },
  {
    label: '型体',
    prop: 'style',
    sortable: true
  },
  {
    label: '颜色',
    prop: 'color',
    sortable: true
  },
  {
    label: '品牌',
    prop: 'brand',
    sortable: true
  },
  {
    label: '下单日期',
    prop: 'orderDate',
    sortable: true
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
const getTableList = async () => {
  isLoading.value = true
  const result = await service.post<any, any>(
    `/mes/kf/summaryOperation/getNotSummaryLotNoList?pageNum=${currentPage.value}&pageSize=${pageSize.value}`,
    {
      sumNo: formList.value.find((item: any) => item.inputPlaceholder === '请输入汇总号')?.inputValue,
      lotNo: formList.value.find((item: any) => item.inputPlaceholder === '请输入指令号')?.inputValue,
      mtlNo: formList.value.find((item: any) => item.inputPlaceholder === '请输入物料编码')?.inputValue,
      deptType: 2
    }
  )
  tableData.value = result.rows
  total.value = result.total
  isLoading.value = false
}
const selectTableList = ref([])
const selectList = (val: any) => {
  selectTableList.value = val
}
const currentTableRow = ref([])
const currentRow = (val: any) => {
  currentTableRow.value = val
}
onMounted(() => {
  getTableList()
  getTableList3()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)

// 汇总材料查询
const currentTableRow2 = ref([])
const currentRow2 = (val: any = tableData2.value[0]) => {
  currentTableRow2.value = val
  getTableList5()
}
const selectTableList2 = ref([])
const selectList2 = (val: any) => {
  selectTableList2.value = val
}
const tableData2 = ref([])
const total2 = ref(0)
const getTableList2 = async () => {
  isLoading2.value = true
  const result = await service.post<any, any>(`/mes/kf/summaryOperation/getSummaryMaterialList`, {
    ...currentTableRow3.value
  })
  if (result.code === 200) {
    tableData2.value = result.rows
    total2.value = result.total
    currentRow2()
  } else {
    JMessage.error(result.msg)
  }
  isLoading2.value = false
}

// 汇总号与资料查询
const currentPage3 = ref(1)
const pageSize3 = ref(40)
const handleSizeChange3 = (val: number) => {
  pageSize3.value = val
  getTableList3()
}
const handleCurrentChange3 = (val: number) => {
  currentPage3.value = val
  getTableList3()
}
const tableData3 = ref([])
const total3 = ref(0)
const getTableList3 = async () => {
  isLoading3.value = true
  const result = await service.post<any, any>(
    `/mes/kf/summaryOperation/getSummaryLotNoList?pageNum=${currentPage3.value}&pageSize=${pageSize3.value}`,
    {
      lotNo: formList.value.find((item: any) => item.inputPlaceholder === '请输入指令号')?.inputValue,
      sumNo: formList.value.find((item: any) => item.inputPlaceholder === '请输入汇总号')?.inputValue,
      mtlNo: formList.value.find((item: any) => item.inputPlaceholder === '请输入物料编码')?.inputValue
    }
  )
  tableData3.value = result.rows
  currentRow3()
  total3.value = result.total
  isLoading3.value = false
}
const currentTableRow3 = ref({}) as any
const currentRow3 = (val: any = tableData3.value[0]) => {
  currentTableRow3.value = val
  getTableList2()
}
const selectTableList3 = ref([])
const selectList3 = (val: any) => {
  selectTableList3.value = val
}

// 贴合子资料查询
const currentPage5 = ref(1)
const pageSize5 = ref(40)
const handleSizeChange5 = (val: number) => {
  pageSize5.value = val
  getTableList5()
}
const handleCurrentChange5 = (val: number) => {
  currentPage5.value = val
  getTableList5()
}
const tableData5 = ref([])
const total5 = ref(0)
const getTableList5 = async () => {
  isLoading5.value = true
  const result = await service.post<any, any>(`/mes/kf/summaryOperation/getBondingSubmaterial`, {
    ...currentTableRow3.value,
    ...currentTableRow2.value
  })
  tableData5.value = result.rows
  total5.value = result.total
  isLoading5.value = false
}

const tableHeader2 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '用量',
    prop: 'ttlUsage'
  },
  {
    label: '预加量',
    prop: 'advanceUsage'
  }
])
const tableHeader3 = ref([
  {
    label: '汇总号',
    prop: 'sumNo'
  },
  {
    label: '汇总日期',
    prop: 'createTime'
  },
  {
    width: 120,
    label: '指令号',
    prop: 'lotNo'
  },
  // {
  //   label: '型体',
  //   prop: 'style'
  // },
  // {
  //   label: '配色',
  //   prop: 'color'
  // },
  {
    label: '工厂货号',
    prop: 'style'
  },
  {
    label: '颜色',
    prop: 'color'
  },
  {
    label: '品牌',
    prop: 'brand'
  },
  {
    label: '纸板号',
    prop: 'shoeName'
  },
  {
    label: '号码',
    prop: 'sizeNo'
  },
  // {
  //   label: '指令类型',
  //   prop: 'lotType'
  // },

  {
    label: '订单量',
    prop: 'orderQty'
  }
  // {
  //   label: '预补数',
  //   prop: 'surplusQty'
  // }
])
const tableHeader4 = ref([
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  }
])
const tableHeader5 = ref([
  {
    label: '指令',
    prop: 'lotNo'
  },
  {
    label: '物料编码',
    prop: 'mtlNo'
  },
  {
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    label: '材料名称',
    prop: 'mtlName'
  },
  {
    label: '规格',
    prop: 'mtlSpec'
  },
  {
    label: '单位',
    prop: 'mtlUnit'
  },
  {
    label: '用量',
    prop: 'ttlUsage'
  },
  {
    label: '预加量',
    prop: 'advanceUsage'
  }
])

const tableHeader7 = ref([
  {
    label: '指令',
    prop: 'lotNo'
  }
])
</script>

<style lang="less" scoped>
.main {
  width: 100%;
}
</style>
